﻿using System;
using System.Windows;
using MOCSoftware.Utilities.JpgMetaDataViewer.Model;
using MOCSoftware.Utilities.JpgMetaDataViewer.Viewmodel;

namespace MOCSoftware.Utilities.JpgMetaDataViewer
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            var window = new MainWindow();

            var jpgManager = new JpgManager();
            var imageViewModel = new ImageViewModel(jpgManager);
            var metaDataViewModel = new MetaDataViewModel(jpgManager);
            var aboutViewModel = new AboutViewModel();

            var viewModel = new MainWindowViewModel(jpgManager, imageViewModel, metaDataViewModel, aboutViewModel);
            viewModel.Initialise();

            imageViewModel.Initialise();

            EventHandler onRequestClose = null;
            onRequestClose = delegate
            {
                viewModel.RequestClose -= onRequestClose;
                window.Close();
            };

            viewModel.RequestClose += onRequestClose;

            window.DataContext = viewModel;

            window.Show();
        }
    }
}
